package luongvd.handyenglish.model.adapter;

import java.util.ArrayList;

import luongvd.handyenglish.R;
import luongvd.handyenglish.model.object.ObjectItemMenu;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AdapterMenu extends ArrayAdapter<ObjectItemMenu>{

	Activity activity;
	ArrayList<ObjectItemMenu> arrayList;
	ObjectItemMenu objectItemMenu;
	LayoutInflater layoutInflater;
	
	public AdapterMenu(Activity activity, ArrayList<ObjectItemMenu> objects) {
		super(activity, R.layout.item_list_menu, objects);
		this.arrayList = objects;
		this.activity = activity;
		layoutInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = layoutInflater.inflate(R.layout.item_list_menu, null);
			holder.icon = (ImageView)convertView.findViewById(R.id.item_menu_icon);
			holder.title = (TextView)convertView.findViewById(R.id.item_menu_text);
			convertView.setTag(holder);
		}
		else {
			holder = (ViewHolder)convertView.getTag();
		}
		objectItemMenu = new ObjectItemMenu();
		objectItemMenu = arrayList.get(position);
		holder.icon.setImageResource(R.drawable.ic_launcher);
		holder.title.setText(objectItemMenu.getTitle());
		return convertView;
	}

	class ViewHolder{
		ImageView icon;
		TextView title;
	}
}
